package com.huiquan.vocab.dao;

import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.vocab.domain.VocabElementClassify;
import com.ibatis.sqlmap.client.SqlMapClient;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class VocabElementClassifyDao extends EnhancedBaseDao<VocabElementClassify> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "VOCAB_ELEMENT_CLASSIFY.";

	public VocabElementClassifyDao() {
		super(space);
	}

	public void init() {
		this.update(space + "INIT", sqlMapClient);
	}

	public void uncheckByCategory(String category) {
		this.update(space + "UNCHECK_BY_CATEGORY", category, sqlMapClient);
	}

	public VocabElementClassify retrieveObjectByNameAndProperty(String name, String property) {
		Map<String, Object> param = new HashMap<>();
		param.put("name", name);
		param.put("property", property);

		return (VocabElementClassify) this.object(space + "RETRIEVE_OBJECT", param, sqlMapClient);
	}

	public void checkByIds(String ids) {
		this.update(space + "CHECK_BY_IDS", ids, sqlMapClient);
	}

	public void updateParentByElement(String element, String parent) {
		Map<String, Object> param = new HashMap<>();
		param.put("element", element);
		param.put("parent", parent);

		this.update(space + "UPDATE_PARENT_BY_ELEMENT", param, sqlMapClient);
	}

	public void insertOrganLines(List<String> lineList) {
		this.insert(space + "INSERT_ORGAN_LINES", lineList, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrieveOrganLinesByElement(String element) {
		return (List<String>)this.list(space + "RETRIEVE_ORGAN_LINES_BY_ELEMENT", element, sqlMapClient);
	}

	public void deleteOrganLines() {
		this.delete(space + "DELETE_ORGAN_LINES", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrieveOrganLines() {
		return (List<String>)this.list(space + "RETRIEVE_ORGAN_LINES", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<VocabElementClassify> retrieveAllForExport(String checkFlag) {
		Map<String, Object> param = new HashMap<>();
		if(StringUtils.isNotBlank(checkFlag)){
			param.put("checkFlag", checkFlag);
		}
		return (List<VocabElementClassify>)this.list(space + "RETRIEVE_ALL_FOR_EXPORT", param,sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<VocabElementClassify> retrieveConflict() {

		return (List<VocabElementClassify>)this.list(space + "RETRIEVE_CONFLICT", sqlMapClient);

	}
}
